<?php
	class Mconfigcamera extends CI_Model{
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function list_camera_name()
		{
			$result=$this->db->query("select id, name from configcamera");
			return $result->result_array();
		}
		public function show_result($search_area, $check_all, $date_from, $hour_from, $minute_from, $date_to, $hour_to, $minute_to, $car_num, $regcognize, $car_type, $page)
		{
			$start=$page*10;
			$format_date_from=$date_from." ".$hour_from.":".$minute_from;
			$format_date_to=$date_to." ".$hour_to.":".$minute_to;
			$query="select idx, car_datetime, carnumber, name, host, filename
					from carnum inner join configcamera on carnum.id=configcamera.id
					where 1";
			if($check_all==0)
				$query.=" and configcamera.id='$search_area'";
			if($regcognize!=-1)
				$query.=" and isReg='$regcognize'";
			if($car_type!=-1)
				$query.=" and car_type='$car_type'";
			$query.=" and carnumber like '%$car_num%' and car_datetime BETWEEN '$format_date_from' and '$format_date_to' limit $start,10";
			$result=$this->db->query($query);
			// return $result->num_rows();
			return $result->result_array();
			// echo $car_num;
			// return $query;
		}
		public function total_result($search_area, $check_all, $date_from, $hour_from, $minute_from, $date_to, $hour_to, $minute_to, $car_num, $regcognize, $car_type)
		{
			$format_date_from=$date_from." ".$hour_from.":".$minute_from;
			$format_date_to=$date_to." ".$hour_to.":".$minute_to;
			$query="select idx
					from carnum inner join configcamera on carnum.id=configcamera.id
					where 1";
			if($check_all==0)
				$query.=" and configcamera.id='$search_area'";
			if($regcognize!=-1)
				$query.=" and isReg='$regcognize'";
			if($car_type!=-1)
				$query.=" and car_type='$car_type'";
			$query.=" and carnumber like '%$car_num%' and car_datetime BETWEEN '$format_date_from' and '$format_date_to'";
			$result=$this->db->query($query);
			return $result->num_rows();
		}
	}
?>